<template>
  <page-layout>
    <a-spin :spinning="isLoading">
      <a-card>
        <footer-button :buttons="state.buttons" />
        <a-form>
          <a-row type="flex" justify="space-between">
            <a-col
              :span="item.span"
              v-for="item in baseFields.fields"
              :key="item.field"
            >
              <a-form-item :label="item.title" class="mb-5">
                {{ handleFormEmptyData(baseFields.data[item.field]) }}
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
        <a-tabs :active-key(v-model)="activeKey" size="small">
          <a-tab-pane key="detail" tab="详情">
            <DetailBaseForm :data="baseFields.data" />
          </a-tab-pane>
        </a-tabs>
      </a-card>
    </a-spin>
  </page-layout>
</template>
<script>
export default {
  name: "order-manage-detail"
}
</script>
<script setup>
import { reactive, onActivated, createVNode, ref } from "vue";
import { message, modal } from "ant-design-vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import { useRoute, useRouter } from "vue-router";
import { handleFormEmptyData } from "@/tools/filters";
import { getDictByCodesReturnObj } from "@/tools/get-dict";
import dictEnum from "@/const/dict";
import { isEmpty } from "@/tools/common";
import DetailBaseForm from "./components/detail-base-form";
import {
	selectById,
} from "@/api/module/student/order-manage";
import { useI18n } from "vue-i18n";
import moment from "moment";
const {	t } = useI18n();
const route = useRoute();
const router = useRouter();
const isLoading = ref(false);
const state = reactive({
  buttons: [
    {
      name: "adjust",
      event: () => handleAdjust(),
      type: "primary",
      code: "",
    },
  ],
  commisType: 0,
});

const handlePay = () => {};
const handleAdjust = () => {
  router.push({
    path: "/studentrtv/order-manage/add",
    query: { id: baseFields.data.id || '' },
  });
};

const baseFields = reactive({
  fields: [
    { title: t('order-manage.label.stuName'), field: "stuName", span: 6 },
    { title: t('order-manage.title.stuuniversity'), field: "colName", span: 6, },
    { title: t('order-manage.title.stuzjNum'), field: "paperNum", span: 6, },
    { title: t('order-manage.title.urgPhone'), field: "localPhone", span: 6, },
  ],
  data: {},
  dict: {},
});
const getDataByDict = (data, dictKey) => {
  if (isEmpty(data)) return "-";
  const item = baseFields.dict && baseFields.dict[dictKey] && baseFields.dict[dictKey].find((v) => v.value == data);
  if (isEmpty(item)) return "-";
  return item.label;
};

onActivated(async () => {
  const result = route.query;
  if (!result || !result.id) return;
  baseFields.dict = await getDictByCodesReturnObj([
    dictEnum.CLASS_STATUS,
		dictEnum.PAY_STATUS,
		dictEnum.FOLLOW_PROGRESS,
		dictEnum.YEARS,
		dictEnum.SEMESTER,
		dictEnum.QUARTER,
		dictEnum.YES_OR_NO,
		dictEnum.CURRENCY,
		dictEnum.PAY_TYPE,
		dictEnum.RECNAME,
		dictEnum.RECAMT,
		dictEnum.PRE_TYPE,
		dictEnum.COURSE_TYPE,
  ]);
	

  isLoading.value = true;
  let res = await selectById({ id: result.id });
  if (res.code === 500) return message.error("获取详情失败");
	res.data = {
		...res.data,
		buspId: res.data.stuBusp.id,
		stuName: res.data.stuBusp.stuName,
		colName: res.data.stuBusp.colName,
		paperNum: res.data.stuBusp.paperNum,
		localPhone: res.data.stuBusp.localPhone
	}
	res.data.isSpecial = getDataByDict(res.data.isSpecial, dictEnum.YES_OR_NO);

	res.data.orderPolicyList && res.data.orderPolicyList.map(item => {
		item.preType = getDataByDict(item.preType, dictEnum.PRE_TYPE);
	})
	
  baseFields.data = res.data;
  isLoading.value = false;
});
</script>

<style>
</style>